home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / basic / getcpu.zip / GETCPU2.ASM < prev    next >
Assembly Source File  |  1990-08-30  |  3KB  |  68 lines

  1. ;=== GetCPU2.ASM - returns the CPU type as 86, 286,386, or 486 ===
  2. ;
  3. ;Cliff Brown  8-30-90
  4. ;
  5. ;=================================================================
  6. ;Based on samples and articles from Jeff Prosise @ PC Magazine and
  7. ;other misc. code bits from CIS and Ethan Winer @ Crescent Software
  8. ;Compiled in MASM 5.1. Tested in QB4.5, BC7.0 and BC7.1
  9. ;=================================================================
  10. ;
  11. ;BASIC use syntax :     DECLARE FUNCTION GetCPU2%
  12. ;                       PRINT "CPU = 80"; GetCPU2%
  13.  
  14. .Model Medium,BASIC
  15. .Code
  16.  
  17. GetCPU2 Proc
  18.          pushf                           ;Save old flags
  19.  
  20.          mov     dx,86                   ;Test for 8086
  21.          push    sp                      ;If SP decrements before
  22.          pop     ax                      ;a value is PUSHed
  23.          cmp     sp,ax                   ;it's a real-mode chip
  24.          jne     Exit                    ;8088,8086,80188,80186,NECV20/V30
  25.  
  26.          mov     dx,286                  ;Test for 286
  27.          pushf                           ;If NT (Nested Task)
  28.          pop     ax                      ;bit (bit 14) in the
  29.          or      ax,4000h                ;flags register
  30.          push    ax                      ;can't be set (in real mode)
  31.          popf                            ;then it's a 286
  32.          pushf
  33.          pop     ax
  34.          test    ax,4000h
  35.          jz      Exit
  36.  
  37.          mov     dx,386                  ;Test for 386/486
  38.          .386                            ;do some 32-bit stuff
  39.          mov     ebx,esp                 ;Zero lower 2 bits of ESP
  40.          and     esp,0FFFFFFFCh          ;to avoid AC fault on 486
  41.          pushfd                          ;Push EFLAGS register
  42.          pop     eax                     ;EAX = EFLAGS
  43.          mov     ecx,eax                 ;ECX = EFLAGS
  44.          xor     eax,40000h              ;Toggle AC bit(bit 18)
  45.                                          ;in EFLAGS register
  46.          push    eax                     ;Push new value
  47.          popfd                           ;Put it in EFLAGS
  48.          pushfd                          ;Push EFLAGS
  49.          pop     eax                     ;EAX = EFLAGS
  50.          and     eax,40000h              ;Isolate bit 18 in EAX
  51.          and     ecx,40000h              ;Isolate bit 18 in ECX
  52.          cmp     eax,ecx                 ;Is EAX and ECX equal?
  53.          je      A_386                   ;Yup, it's a 386
  54.          mov     dx,486                  ;Nope,it's a 486
  55. A_386:
  56.          push    ecx                     ;Restore
  57.          popfd                           ;EFLAGS
  58.          mov     esp,ebx                 ;Restore ESP
  59. Exit:
  60.          mov     ax,dx                   ;Put CPU type in AX
  61.          popf                            ;Restore old flags
  62.          ret                             ;Return to BASIC
  63.  
  64. GetCPU2 Endp
  65. End
  66.  
  67. ;==============================================================
  68.